<template>
    <h1>VUE3.0学习---数据解构后需要使用Toxxx进行转换</h1>
    <div class = "test1">
        <h2>ToRef/s</h2>
        <p>姓名：{{ person.name }}</p>
        <p>年龄：{{ person.age }}</p>
        <button @click="changeData">修改</button>
    </div>
</template>

<script lang="ts" setup>
    import {ref,reactive,toRefs} from 'vue'

    let person = reactive({
        name:"张三",
        age:18
    })

    //解构数据
    let {name,age} = toRefs(person)
    console.log("name:",name,"age:",age)
    //修改数据
    function changeData(){
        // name.value = "李四"
        // age.value = 20
        Object.assign(person,{name:"王五",age:22})
        console.log(person)
    }
</script>

<style scoped>
 .test1{
    font-size: 20px;
    color: blue;
    background-color: greenyellow;
    border: 2px solid #007bff; /* 设置边框的宽度和颜色 */
    border-radius: 20px; /* 将四个角变成圆形 */
    width: auto; /* 设置元素的宽度 */
    height: auto; /* 设置元素的高度 */
    padding: 20px;
 }

 button{
    margin: 2px;
 }

</style>